home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows1 / commdem2.zip / COMMDEMO.FRM (.txt) < prev    next >
Visual Basic Form  |  1992-02-03  |  29KB  |  641 lines

  1. Form_CommDemo
  2. Communications Demo
  3. Form1
  4. Timer_CheckInBuf
  5. Timer_ClearStatusWin
  6. Label_ReceiveWin
  7. Recieve Window
  8. Text_ReceiveWin
  9. Label_TransmitWin
  10. Transmit Window
  11. Text_TransmitWin
  12. Label_StatusWinLab
  13. Communications Status
  14. Label_StatusWin
  15. MNU_File
  16. &File
  17. MNU_File_Exit
  18. E&xit
  19. MNU_Connect
  20.     &Connect!
  21. MNU_BaudMenu
  22. &Baud
  23. MNU_BaudRate
  24. &1200
  25. MNU_BaudRate
  26. &4800
  27. MNU_BaudRate
  28. &9600
  29. MNU_Events
  30. E&vents
  31. MNU_Events_CharDetect
  32. &Character Detect
  33. Form_Click
  34. Form_LinkClose
  35. Form_LinkErrorw
  36. LinkErr
  37. Form_LinkExecute
  38. CmdStr`
  39. Cancel
  40. Form_LinkOpenl
  41. @    Form_Load
  42. Screen
  43. Width4
  44. Height4
  45. OpenErrCode/
  46. OpenCommPort
  47.     InBufSize
  48. OutBufSize
  49. ComDev;
  50. MsgBoxCaption
  51. DefMsgCaptionn
  52. BaseComm
  53. carriage
  54. linefeed
  55. OpenCommErr
  56. Form_Unload
  57. OpenCommError
  58. DefaultLineSettings
  59. DefaultEventSettings}
  60. BaudRateT
  61. ByteSizeC
  62. Parity
  63. NOPARITY
  64. StopBits
  65. ONESTOPBIT
  66. RlsTimeOut`
  67. CtsTimeOut
  68. DsrTimeOuts
  69. ModeControl
  70. XonChar
  71. XoffChar
  72. XonLim
  73. XoffLimP
  74. peChar)
  75. EofChar
  76. EvtChar
  77. Label_StatusBar
  78. Caption
  79. SetCommState
  80. SetLineSettings
  81. valuea
  82. enablesV
  83.     containedr
  84. received
  85. fOutX
  86. fDCBw
  87. OpenComm7
  88. SetEventSettings
  89. DCBType
  90. MNU_File_Exit_Click+
  91.     CloseCommZ
  92. Timer_CheckInBuf_Timer
  93. ReadCommJ
  94. InBuf
  95. NumCharsRead
  96. Text_OutWin?
  97. SelStart
  98. SelTextZ
  99. InBuff
  100.     SelLength
  101. number
  102. handshaking
  103. anything~
  104. buffer
  105. displayg
  106. windowF
  107. Text_OutWin_Change[
  108. Text_OutWin_GotFocus
  109. Text_InWinL
  110. Timer_CheckInBuf
  111. Enabled
  112. TrueI
  113. ReadCommInterval)
  114. Interval
  115. ErrFlag
  116. Text_InWin_Change=
  117. Text_InWin_KeyPresss    
  118. KeyAsciiO
  119. CharsWritten
  120.     WriteComm
  121. OutBuff4
  122. entered
  123. Text_ReceiveWin_Change
  124. Text_TransmitWin_Change
  125. Text_TransmitWin
  126. Text_ReceiveWin{
  127. Text_TransmitWin_KeyDown
  128. KeyCode
  129. Shift
  130. Text_TransmitWin_KeyPressE    
  131.     EventAddr
  132. SetCommEventMask
  133. EV_ALL
  134. Timer_ClearStatusBar_Timer!
  135. Label2_Click
  136. ShowStatus7
  137. StatusText
  138. Timer_ClearStatusBar
  139. ClearStatusIntervall
  140. False.
  141. comst
  142. status
  143.     DelayFlage
  144. delay
  145.     DelayTime+
  146. callingU
  147. Windows
  148. IE_OPEN
  149. Response
  150. ShowCriticalMessage/
  151. ShowCritErrMessage
  152. ShowCritErr
  153. Label_ReceiveWin_Click
  154. ErrTypev
  155. ErrCode
  156. @    ShowErrorJ
  157. ExitRoutine
  158. CloseComFlag:
  159. ProcessCommError}
  160. CommErr
  161. GetCommErrorf
  162. COMSTATr
  163. CE_BREAK
  164. CommStat
  165. Message
  166. ShowMessage
  167. CE_CTSTO
  168. CE_STSTO=
  169. CE_DNS
  170. CE_FRAME
  171. CE_IOE
  172. CE_MODE8
  173. CE_OOPX    
  174. CE_OVERRUN
  175. CE_PTO'    
  176.     CE_RLSDTOu
  177.     CE_RXOVERL    
  178. CE_RXPARITY
  179.     CE_TXFULL
  180. COMSTATType
  181. CommConnectB
  182. comments`    
  183. herej    
  184. CommID
  185. ComID
  186. GetCommStateJ
  187. DCB_Type
  188. MNU_Connect_Click
  189. ConnectFlag
  190. MNU_Connect 
  191. CommDisconnect
  192. ConnectErrorr
  193. ConnectErrFlag
  194. IE_BADID
  195. IE_BAUDRATE.
  196. IE_BYTESIZE
  197. IE_DEFAULT
  198. IE_HARDWARE
  199.     IE_MEMORYV
  200. IE_NOPEN
  201. Text_ReceiveWin_GotFocus
  202. CommConnectFlag
  203. COMSTAT_Type5
  204. ShowErrorMessage
  205.     ErrorFlag&
  206. Label_TransmitWin_Click
  207. ProcessCommEvents)
  208.     EventMaskD
  209. GetCommEventMaskL
  210. CurrentEventMaskU
  211. EV_BREAK
  212.     ShowStateV
  213. EV_CTR
  214. EV_CTS`
  215. EV_DSRj
  216. EV_ERR
  217. EV_PERR
  218. EV_RING;
  219. EV_RLSD
  220.     EV_RXCHAR
  221.     EV_RXFLAG
  222.     EV_FXFLAG
  223. EV_TXEMPTY^
  224. DisconnectComm?
  225. Form_CommDemo
  226. Form_Resize
  227. Text_.
  228. TxDelay
  229. cbInQue
  230. cbOutQuet
  231. lpCommName
  232. wInQueue
  233.     wOutQueuej
  234. lpBuf
  235. nSize
  236. nEvtMask
  237. CE_DSRTO
  238.     ODDPARITY
  239. EVENPARITY
  240. ONE5STOPBITS
  241. TWOSTOPBITS
  242. Label_StatusWin
  243. alreadyp
  244. opened
  245. alread
  246. ComDisconnect
  247. MNU_File_Click
  248. events
  249. detectz
  250. Label_StatusWin_ClickU
  251. Label_StatusWinLab_Click
  252. Disconnect
  253. ProcessComError
  254. Visual
  255. Basic
  256. Timer_ClearStatusWine
  257. Timer_ClearStatusWin_Timer
  258. GetOpenCommError
  259.     FlushCommH
  260. BuildCommDCB6
  261. MNU_BaudRate_Click
  262. Index
  263. BaudRate_Click
  264.     LastIndex
  265. MNU_BaudRateT
  266. Checked
  267. PortID
  268. MNU_Baud_Menu
  269. MNU_BaudMenu
  270. MNU_BaudMenu_Click
  271. closed
  272. ComStatusCode
  273.     GlobalDCB|
  274. CharsWaiting'
  275. MNU_Events_CharDetect_Click
  276. CurrEventMask
  277. MNU_Events_Click
  278. MNU_Events_CharDetectg
  279. CharDectEnabled
  280. CharDetectEnabled
  281. CharDetectEnabledFlag
  282. MNU_Eventsx
  283. Name of default communications device to be opened
  284. COM input and output buffer sizess
  285. Time interval to read the COM port (in milliseconds)
  286. The maximum period of time (in milliseconds) for which a status bar message will be displayed
  287. The time that message processing will be delayed (in seconds) while displaying a status bar message
  288. Device Control Block (DCB) for the COM port.  Contains all of the current line settings for the COM port.T
  289. ID number representing the COM port.  Set by calling the Windows API function SetCommState.
  290. Flag indicating successful COM connection.
  291. The current COM event settings. Set by calling the Windows API function SetCommEventMask
  292. Form_Load
  293. * This is the entry point of the program.  Initialize global variables and center the form
  294. * on the screen.  The Windows API function BuildCommDCB is called to assign default values too
  295. * the DCB (Device Control Block) data structure.
  296. Initialize global variables representing carriager
  297. return and carriage return linefeedn
  298. Center the form on the screen
  299. Disable the Events menu.  The Events menu is enabled when the COM is connected
  300. Initialize the COM DCB (Device Control Block) with default line settings
  301. COM1:1200,N,8,1"
  302. Form_Unload
  303. Disconnect the COM only if the COM was connected
  304. from this programh
  305. SetLineSettings
  306. * Set default line settings (e.g. baud rate, parity,
  307. * data bits, stop bits and handshaking) by calling
  308. * the Windows API function SetCommState.
  309. * Note: The Chr$ function is used below to convert a numeric value
  310.  to a 1 byte character value.  This is needed because a byte
  311.  is not supported as a numerical type under Visual Basic.
  312.  The Asc function can be used to get the value of a 1 byte 
  313.  character representing a 1 byte numerical value.
  314. Setting line settings ..."
  315. Set the Id for the COM port.  The COM port ID is returned by the Windows API function OpenComm
  316. Set line settings for the COM port as 1200:N,8,1,CD0,CS0,DS0,RS,TB2048,RB2048t
  317. The following parameter settings represent the default settings set by calling
  318. BuildCommDCB in the Form_Load event procedure.
  319. Set parameters as 1200: N,8,1M
  320. DCB.BaudRate = 1200
  321.  'Other possible values include 300, 2400, 4800, 9600, 19200.
  322. DCB.ByteSize = Chr$(8)
  323.  'Other possible values include 4,5,6,7 
  324. DCB.Parity = Chr$(NOPARITY)
  325.  'Other possible values include EVENPARITY, MARKPARITY, ODDPARITY, SPACEPARITY
  326. DCB.StopBits = Chr$(ONESTOPBIT) 'Other possible values include ONE5STOPBITS, TWOSTOPBITS
  327. Set timeout period for CD, CS and DS handshake lines respectively.  Values
  328. represent milliseconds.  A value of zero represents an infinite wait effectively
  329. disabling handshaking on that line.  Possible values can range from 0 to 65,535s
  330. for an unsiged integer or -32,768 to 32,767 for signed integers.
  331. Carrier detect or receive-line-signal-detect (CD or RLSD) line (CD0)
  332. Clear-to-send (CTS) line (CS0)
  333. Data-set-ready (DSR) line (DS0))
  334. The following bit flags are combined in the ModeControl field below.  Becausec
  335. the following are bit fields they cannot be represented as a field of a Type ... End Type 
  336. structurew
  337. DCB.fBinary = 1
  338.  Specify binary mode.  Setting this to zero causes an
  339.  EOF character (Chr$(26)) to signal the end of data.
  340. DCB.fRtsDisabled = 1
  341.  Disable request-to-send line (RS).  A zero value enables
  342.  the request-to-send linev
  343. DCB.fParity = 0
  344.  Disable parity checking.  A value of 1 enables parity checking
  345. DCB.fOutCtsFlow = 0
  346.  Disable checking of clear-to-send line for output flow control
  347. DCB.fOutxDsrFlow = 0
  348.  Disable checking of data-set-ready (DSR) line for output flow control
  349. DCB.fDummy = 0 + 0
  350.      Two bit reserved fieldd
  351. DCB.fDtrDisabled = 1
  352.  Disable the data-set-ready line (DTR).  A value of 1 enables DTR.
  353. DCB.fOutX = 0
  354.  Disable XON/XOFF during transmission.e
  355.  A value of 1 enables XON/XOFF.d
  356. DCB.fInX = 0
  357.  Disable XON/XOFF during reception.i
  358.  A value of 1 enables XON/XOFF
  359. DCB.fPeChar = 0
  360.  Disable the replace of parity error characters with the character 
  361.  contained in the PeChar field.  A value of 1 enables replacementt
  362.  of parity error characters with the character contained in then
  363.  PeChar field.
  364. DCB.fNull = 0
  365.  Received null characters are not to be discarded.  A value of 1c
  366.  specifies that null characters received will be discarded.d
  367. DCB.fChEvt = 0
  368.  Reception of the character contained in the EvtChar field doesc
  369.  not signify an event.  A value of 1 indicates that thet
  370.  reception of a character identical to the character contained
  371.  in the EvtChar field signifies and event.
  372. DCB.fDtrFlow = 0
  373.  The DTR line is not used for receive flow control.  A value of 1 
  374.  indicates that the DTR line is used for receive flow control.
  375. DCB.fRtsFlow = 0
  376.  The RTS line is not used for receive flow control.  A value of 1 
  377.  indicates that the DTR line is used for receive flow control.
  378. DCB.fDummy = 0
  379.  Reserved 
  380. 1100 0001 
  381.  Binary representationr
  382.  of the above bit settings
  383.      Hex representation of the aboveu
  384.  bit settings 
  385. Based on the bit settings above 
  386. XON character to be used.  Only used if the fOutX or fInX 
  387. fields are set to 1.
  388. XOFF character to be used.  Used only if the fOutX or fInX
  389. fields are set to 1.
  390. Specifies minimum number of characters allowed in the receive
  391. buffer before the XON character is sent.  Used only if the fOutX
  392. or fInX fields are set to 1.
  393. Specifies the maximum number of characters allowed in the
  394. receive buffer before the XOFF character is sent.  Used only
  395. if the fOutX or fInX fields are set to 1.i
  396. Character used to replace characters received with a parity
  397. error.  Used only if the fPeChar flag has been set to 1.
  398. Specifies the character used to indicate end of data.  Used
  399. only if the the fBinary flag is set to 0.t
  400. Character indicating an event.  Used only if the fChEvt flag
  401. is set to 1.
  402. MNU_File_Exit_Click
  403. * When the user selects Exit from the File menu, unload thee
  404. * form, disconnect the COM - if it is already opened - and
  405. * end the programm
  406. Timer_CheckInBuf_Timer
  407. * The code below represents a method of reading the COM port
  408. * by calling the Windows API function ReadComm..
  409. * Check the input buffer on each timer interval by calling
  410. * the Windows API function ReadComm.  If anything is found
  411. * in the buffer, display it in the receive window.
  412. COM status variable used by the Windows API function GetCommErrorb
  413. Allocate a buffer (a text string of spaces) the size of the specified input buffer.f
  414. Because the ReadComm API function expects to read to an existing buffer, failing
  415. to initialize the buffer may result in unpredictable results or a Windows UAE.
  416. Unlock the COM port if it had been locked as the result of a previous COM error.
  417. The number of characters waiting in the receive buffer will be returned as part of the COMSTAT structure
  418. Check to see if there are any characters waiting in the receive buffer
  419. Call the Windows API function to read information from the input buffer.  Read
  420. all characters waiting in the input buffer.m
  421. Check for COM error by calling the Windows API function GetCommError
  422. If a COM error occurs, a message will be displayed and the COM port disconnected.f
  423. Check for COM events by calling the Windows API function GetCommEventMask.
  424. COM events, such as a ring detect, are displayed in the status window as they occur.
  425. Check to see if any characters were read from the input buffer
  426. Display the text read from the input buffer in
  427. the receive window
  428. SetEventSettings
  429. * Specify which events are allowed to occur by calling the Windows API function
  430. * SetCommEventMask..
  431. Setting event settings ...
  432. Place a check mark next to the Events menu item Character Detect indicating that char detect has been enabled
  433. The following communication events are to be processed
  434.    Event (constant)
  435.  Descriptions
  436.    EV_BREAK
  437.  Set when a break is detected on input-
  438.    EV_ERR
  439.  Set when a line-status (CE_FRAME, CE_OVERRUN, CE_RXPARITY) error occurso
  440.    EV_RING
  441.  Set when a ring indicator is detected
  442.    EV_RXCHAR
  443.  Set when a character is received and placed in the COM receive buffer
  444.    EV_TXEMPTY
  445.  Set when the last character in the COM transmit buffer is sent
  446. Other possible values include:
  447.    EV_CTS
  448.  Set when the clear-to-send (CTS) signal changes stateu
  449.    EV_DSR
  450.  Set when the data-set-ready (DTR) signal changes state
  451.    EV_PERR
  452.  Set when a printer error is detected on a parallel device
  453.    EV_RLSD
  454.  Set when the receive-line-signal-detect (RLSD) signal changes state
  455.    EV_RXFLAG
  456.  Set when the event character is received and placed in the receive buffer
  457. Combine the events to be processed into the event mask.  The bitwise Or operator is used toi
  458. combine the bit patterns of the constants representing the COM events.
  459. All possible communciations events may occur
  460. Text_TransmitWin_KeyPress
  461. * Writes the character for each key press to the output*
  462. * buffer by calling the Windows API function WriteComm
  463. Convert the ASCII code of the key pressed to an ASCII characterr
  464. Write the character to the COM output buffer by callingl
  465. the Windows API function WriteComm.u
  466. Check for COM error by calling the Windows API function GetCommError
  467. If a COM error occurs, a message will be displayed and the COM port 
  468. disconnected.r
  469. Check for COM events.  COM events, such as a ring detect, are,
  470. displayed in the status window as they occur.r
  471. ShowStatus
  472. * Display a caption within the status window at the bottom
  473. * of the main display window
  474. Show a message in the status window 
  475. Delay (allow for the message to be read by the user) for
  476. a specified period of time
  477. Get the current clock count 
  478. Loop for the amount of time specified by DelayTime (in seconds) without processing other Windows events
  479. Enable a timer to cause the status window to be clear after a specified period of time
  480. ShowError
  481. * Display standard error messages based on the type of error that occurred..
  482. * The messages are displayed in a modal message box (MsgBox).
  483. Show message box indicating that an error occurred
  484. attempting to open the COM port 
  485. Error occurred attempting to open 
  486. Connection not established
  487. Error attempting to set line settings"
  488. Connection not established
  489. ProcessCommError
  490. * Determines if an error occurred after a COM operation. *
  491. * If an error occurred, a message is displayed indicating that the COM will be
  492. * disconnected.  It is the responsibility of the calling routine to disconnect
  493. * the COM.
  494. * When an error occurs, Windows locks the COM port.  Calling the
  495. * Windows API function GetCommError causes the COM port to be unlocked.
  496. COM status variable used by the Windows API function GetCommErrorE
  497. Find out if an error occured.  Calling GetCommError clears
  498. the error and causes Windows to unlock the COM port.
  499. One or more of the following errors may have occurred 
  500. Break condition detected
  501. Clear-to-send (CTS) timeout"
  502. Data-set-ready (DSR) timeout
  503. Parallel device is not selected"
  504. Framing error detected
  505. Device I/O error occurred"
  506. attempting to communicate with parallel device
  507. Requested mode is not supported"
  508. Out of paper on parallel device"
  509. Overrun error detected
  510. Timeout attempting to communicate with
  511. parallel device"
  512. Receive-line-signal-detect (RLS) timeout
  513. Receive buffer overflow"
  514. Parity error detected"
  515. Transmit buffer full
  516. CommConnect
  517. * Connect to the communications port by calling the following Windows API functions:
  518.  OpenComm
  519.  GetCommState
  520.  SetCommState
  521.  SetCommEventMask
  522. * The return values of OpenComm and SetCommState are tested for an error.  If an
  523. * error occurs a message is displayed and the COM remains disconnected.r
  524. Assume that no error will occur opening COMr
  525. Opening COM port ...
  526. Attempt to open the COM port specifying the input and output buffer sizes 
  527. Check to see if the COM port was successfully opened
  528. If the COM was successfully opened the return value of OpenComm represents the COM ID.
  529. Set communications line settings such as baud rate,d
  530. parity, data bits, stop bits and hardware handshaking.
  531. Select the allowable communication events 
  532. by calling the Windows API function SetCommEventMask
  533. Display a message box indicating a critical error and
  534. end the programg
  535. Enable the timer to begin reading the COM input buffer.t
  536. Get the COM ID used in the call to BuildCommDCBa
  537. COM device already opened"
  538. Do you wish to use it anyway
  539. Close the com port if the user selected Yes from the message box
  540. The user chose not to use the COM port that is already opened.
  541. Show a critical error and terminate the programa
  542. A critical error occurred when attempting to open the COM port.p
  543. Attempt to open the COM port again if the COM port is already open, but the user wants to use it anyway
  544. Return False if an error occurred attempting to connectn
  545. Return True if connection was successful
  546. MNU_Connect_Click
  547. * When the user selects Connect! from the menu, connect to the COM port if itt
  548. * is not already opened by calling CommConnect.
  549. * When the user selects Disconnect! from the menu, disconnect from the COM
  550. * port if it is already opened by calling ComDisconnect.
  551. See if the COM is already a connected
  552. Disconnect the COM port by calling the Windows API function CloseComms
  553. Connect to the COM port by calling the following Windows API functions:u
  554.    OpenComm 
  555.    SetCommStateM
  556.    SetCommEventMaskS
  557. Make sure there was no error in connecting to the COM port.C
  558. If an error occurred, no attempt will be made to connect the COM port.
  559. &Disconnect!
  560. Enable the transmit and receive windowss
  561. CommDisconnect
  562. * Disconnect from the COM port by calling the Windows API function CloseComm
  563. * Disable the transmit and receive windows and reset the menu caption.
  564. Closing COM port ...
  565. Flush the transmit buffer
  566. Flush the receive buffer
  567. Call the Windows API function to close the COM port.
  568. The return value represents whether the comm was successfully closed or not, it is
  569. not used.n
  570. Invalid the COM ID to indicate that the COM was closed
  571. Turn off timer used to check COM receive bufferu
  572. Disable the transmit and receive windows
  573. Change the menu caption and connection status flag
  574. &Connect!"
  575. Disable the events menua
  576. Text_ReceiveWin_GotFocus
  577. * Do not allow the focus to be set to the receive window.*
  578. * If the user attempts to select the receive window,
  579. * restore focus to the transmit window.c
  580. ProcessCommEvents
  581. * Check to see if a communications event occurred by calling the Windows
  582. * API function GetCommEventMask.  The event, such as a ring, is reported
  583. * in the status window.v
  584. Call Windows API function to get the COM event mask.  The event mask iss
  585. a pattern of bits which represents one or more of the events below.n
  586. Check for the following events.  The events that are reported 
  587. are dependent on the event mask that was passed to SetCommEventMaskt
  588. Break detected on input"
  589. Clear-to-send (CTS) line changed state
  590. Data-set-ready (DTR) line changed state"
  591. Line status (framing, overrun or parity) error occurred"
  592. Printer error occurred
  593. Ring detected"
  594. Receive-line-signal-detect (RLSD) or carrier-detect (CD) line changed status
  595. Character received
  596. Event character received
  597. Last character sent: transmit buffer empty
  598. Timer_ClearStatusWin_Timer
  599. * After a status message has been displayed 
  600. * for a certain interval, clear the status window-
  601. GetOpenCommError
  602. * FUNCTION: GetOpenCommError
  603. * PURPOSE:  Returns an error message based on the specified
  604.  error code.  The error code is interrupted as 
  605.  related to an error when opening the COM device.
  606.  This function handles all possible return codes.
  607.  from the Windows API function OpenComm.r
  608. * PARMS:
  609.  OpenErrCode - Specifies the error code relatede
  610.  to the opening the COM porti
  611. * RETURNS:  A string containing the error message associated
  612.  with the error coden
  613. Invalid or unsupported ID"
  614. Unsupported baud rate"
  615. Invalid byte size"
  616. Error in default parameters"
  617. Hardware not present
  618. Unable to allocate queues"
  619. Device not open"
  620. Device already opened"
  621. MNU_BaudRate_Click
  622. * Change the COM line settings to reflect the new baud rate selected by the user..
  623. * Note that the baud rate (as with any line setting) can be changed if the portt
  624. * is open or closed.  If the baud rate of the device being communicated with doess
  625. * not change, this could lead to unexpected behavior..
  626. Get the baud rate selected
  627. Set the baud rate 
  628. Modify the COM line settings with the new baud rate
  629. Put a check mark next to the baud rate selectedr
  630. Take the check mark away from the last baud rate selectedl
  631. MNU_Events_CharDetect_Click
  632. * Set or disable the ability to detect characters received
  633. * from the COM.
  634. * When enabled, character related events are displyed in
  635. * the status window when a character is received
  636. Get the status of the menu selection
  637. Toggle the check mark next to the menu itemv
  638. Disable character detect events by setting the EV_RXCHAR bit to 0e
  639. Enable character detect events by setting the EV_RXCHAR bit to 1
  640. Set the COM event settings by calling a Windows API function
  641.